package com.epam.facebook_client;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.epam.facebook_client.api.API;
import com.epam.facebook_client.task.PostStringAsyncTask;

public class PostStatusActivity extends Activity {

	private static final String MASSAGE = "message";
	protected static final String TAG = PostStatusActivity.class.getSimpleName();

	// TODO image view touch base

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_post);
		Button postButton = (Button) findViewById(R.id.postButton);
		final EditText statusEditText = (EditText) findViewById(R.id.editMultiText);
		final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
		progressBar.setVisibility(View.GONE);
		postButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				final Map<String, String> hashMap = new HashMap<String, String>();
				hashMap.put(MASSAGE, statusEditText.getText().toString());
				new PostStringAsyncTask(getBaseContext(), progressBar) {

					@Override
					public void success(String result) {
						Toast.makeText(getApplication(), "Posted", Toast.LENGTH_SHORT).show();
					}

					@Override
					public Map<String, String> params() {
						return hashMap;
					}

					@Override
					public void onError(Exception e) {
						Log.i(TAG, "Exception: " + e);
						Toast.makeText(getApplication(), "EXCEPTION", Toast.LENGTH_SHORT).show();
					}
				}.execute(API.FEED_POST);
				finish();
			}
		});

	}
}
